﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MidApp
{
    public class ManageDetail
    {
        /// <summary>
        ///Metoda ulozi novy detail do databaze podle teamID a userID.
        ///</summary>
        public static void CreateNewDetail(AppLib.Detail newDetail, int teamID, int userID)
        {
            var db = MidApp.LinqUse.DBConn;

            db.Details.InsertOnSubmit(newDetail);
            db.SubmitChanges();

            MidApp.ManageIsStockDetail.AssignDetailToUserAndTeam(userID, teamID, newDetail.DetailID);
            
        }
        /// <summary>
        ///Metoda vraci hodnotu, kolik bylo strzeni ci pricteno podle detailID.
        ///</summary>
        public static string GetAmount(int detailID)
        {
            var db = MidApp.LinqUse.DBConn;

            return (from Detail in db.Details where Detail.DetailID == detailID select Detail).First().Amount;
        }
        /// <summary>
        ///Metoda vraci popis detailu.
        ///</summary>
        public static string GetDescription(int detailID)
        {
            var db = MidApp.LinqUse.DBConn;

            return (from Detail in db.Details where Detail.DetailID == detailID select Detail).First().Detail1;
        }
        /// <summary>
        ///Metoda vraci datum detailu.
        ///</summary>
        public static string GetDate(int detailID)
        {
            var db = MidApp.LinqUse.DBConn;

            var date = (from Detail in db.Details where Detail.DetailID == detailID select Detail).First().Date;

            return date.Value.ToShortDateString();
        }
        /// <summary>
        ///Metoda smaze detail z db.
        ///</summary>
        public static void DeleteDetail(int detailID)
        {
            var db = MidApp.LinqUse.DBConn;

            AppLib.Detail detail = (from Detail in db.Details where Detail.DetailID == detailID select Detail).First();
            db.Details.DeleteOnSubmit(detail);
            db.SubmitChanges();
        }
    }
}
